import request from '@/utils/request'

/**
 * 获取预警列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getAlertList(params) {
  return request({
    url: '/api/prediction/alerts/',
    method: 'get',
    params
  })
}

/**
 * 获取预警详情
 * @param {Number} alertId - 预警ID
 * @returns {Promise}
 */
export function getAlertDetail(alertId) {
  return request({
    url: `/api/prediction/alerts/${alertId}/`,
    method: 'get'
  })
}

/**
 * 创建预警
 * @param {Object} data - 预警数据
 * @returns {Promise}
 */
export function createAlert(data) {
  return request({
    url: '/api/prediction/alerts/',
    method: 'post',
    data
  })
}

/**
 * 更新预警
 * @param {Number} alertId - 预警ID
 * @param {Object} data - 更新数据
 * @returns {Promise}
 */
export function updateAlert(alertId, data) {
  return request({
    url: `/api/prediction/alerts/${alertId}/`,
    method: 'put',
    data
  })
}

/**
 * 删除预警
 * @param {Number} alertId - 预警ID
 * @returns {Promise}
 */
export function deleteAlert(alertId) {
  return request({
    url: `/api/prediction/alerts/${alertId}/`,
    method: 'delete'
  })
}

/**
 * 处理预警
 * @param {Number} alertId - 预警ID
 * @param {Object} data - 处理数据
 * @returns {Promise}
 */
export function processAlert(alertId, data) {
  return request({
    url: `/api/prediction/alerts/${alertId}/process/`,
    method: 'post',
    data
  })
}

/**
 * 关闭预警
 * @param {Number} alertId - 预警ID
 * @returns {Promise}
 */
export function closeAlert(alertId) {
  return request({
    url: `/api/prediction/alerts/${alertId}/close/`,
    method: 'post'
  })
}

/**
 * 批量处理预警
 * @param {Object} data - 批量处理数据
 * @returns {Promise}
 */
export function batchProcessAlerts(data) {
  return request({
    url: '/api/prediction/alerts/batch-process/',
    method: 'post',
    data
  })
}

/**
 * 获取预警关联的挽留方案列表
 * @param {Number} alertId - 预警ID
 * @returns {Promise}
 */
export function getRetentionPlans(alertId) {
  return request({
    url: `/api/prediction/alerts/${alertId}/retention-plans/`,
    method: 'get'
  })
}

/**
 * 创建挽留方案
 * @param {Number} alertId - 预警ID
 * @param {Object} data - 挽留方案数据
 * @returns {Promise}
 */
export function createRetentionPlan(alertId, data) {
  return request({
    url: `/api/prediction/alerts/${alertId}/retention-plans/`,
    method: 'post',
    data
  })
}

/**
 * 获取挽留方案详情
 * @param {Number} planId - 挽留方案ID
 * @returns {Promise}
 */
export function getRetentionPlanDetail(planId) {
  return request({
    url: `/api/prediction/retention-plans/${planId}/`,
    method: 'get'
  })
}

/**
 * 更新挽留方案
 * @param {Number} planId - 挽留方案ID
 * @param {Object} data - 更新数据
 * @returns {Promise}
 */
export function updateRetentionPlan(planId, data) {
  return request({
    url: `/api/prediction/retention-plans/${planId}/`,
    method: 'put',
    data
  })
}

/**
 * 删除挽留方案
 * @param {Number} planId - 挽留方案ID
 * @returns {Promise}
 */
export function deleteRetentionPlan(planId) {
  return request({
    url: `/api/prediction/retention-plans/${planId}/`,
    method: 'delete'
  })
}

/**
 * 获取预警统计信息
 * @returns {Promise}
 */
export function getAlertStatistics() {
  return request({
    url: '/api/prediction/alerts/statistics/',
    method: 'get'
  })
}